<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: register.php
| Author: Nick Jones (Digitanium)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "maincore.php";
require_once THEMES."templates/header.php";
include LOCALE.LOCALESET."register.php";
include LOCALE.LOCALESET."user_fields.php";

//Henter avloser id fra URL for å hente riktig kontrakter fra DB
$avloserid=$_GET['avloserid'];
//---------------------------------------------------------------------------------------------------------------------+
//------Funksjon for bekreftelse og sletting av kontrakt mot DB   (Hoppes over hvis ikke slettknappen er trykket)------+
//---------------------------------------------------------------------------------------------------------------------+
if(isset($_GET['slett']))

if(isset($_GET['confirm'])) {
	$sid=$_GET['sid'];
	$confirm=$_GET['confirm'];
	if ($_GET['confirm'] == "ja" )
		{
		$query1="DELETE FROM arbeidskontrakt WHERE arbeidskontraktid=$sid";
		mysql_query($query1);
		header("Refresh: 1; url=lagrekontrakt.php?avloserid=".$_GET['avloserid']."&sjekk=nei");
		}
}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-sletting-av-kontrakt---------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+


//---------------------------------------------------------------------------------------------------------------------+
//----------Funksjon for lagring av kontrakt til DB     (Hoppes over hvis ikke lagreknappen er trykket)----------------+
//---------------------------------------------------------------------------------------------------------------------+
//Henter sjekk fra URL
$sjekk=$_GET['sjekk'];

if($sjekk=="ja") {
	$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
	$theDate2 = isset($_REQUEST["date2"]) ? $_REQUEST["date2"] : "";
	$stilling=$_POST['stilling']; 
	if($theDate > $theDate2) {
		echo" <h1 align='center'>Kontrakten kan ikke slutte f&oslash;r den har begynt!</h1>";
		}else if($theDate == $theDate2) {
			echo" <h1 align='center'>Kontrakten slutter samtidig som den starter!</h1>";
			}
			else if (isset($_POST['type']))
				{
				$selected=implode(',',$_POST['type']);
				$db = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_password']);
				mysql_select_db($GLOBALS['db_name'], $db);  
				$query1="INSERT INTO arbeidskontrakt VALUES ('','$theDate','$theDate2', '$stilling', '$selected', $avloserid, '')";
				mysql_query($query1);
				}
				else { echo "<h1 align='center'>Du m&aring; velge Ansatt Type!</h1>";
					
	}
}
//---------------------------------------------------------------------------------------------------------------------+
//------------------------------------Slutt-på-funksjon-for-lagring-av-kontrakt----------------------------------------+
//---------------------------------------------------------------------------------------------------------------------+


//---------------------------------------------------------------------------------------------------------------------+
//----------Kode for uthenting av kontraktdata fra DB og HTML printing til nettleser----(Utføres ved sidelasting)------+
//---------------------------------------------------------------------------------------------------------------------+

$query="SELECT  arbeidskontraktid, ansettelsesdato, oppsigelsesdato, arbeidskontrakt.avloserid, stillingsprosent, arbeidskontrakt.ansatt_type
		FROM arbeidskontrakt, avloser
		WHERE arbeidskontrakt.avloserid = avloser.avloserid
		AND arbeidskontrakt.avloserid = $avloserid
		ORDER BY arbeidskontrakt.oppsigelsesdato DESC;";
$result=mysql_query($query);
$num=mysql_numrows($result);
//------------
echo "
	<br></br>
	<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='profil.php?avloserid=$avloserid'><b><---  Tilbake til profil</b></a></p>
	<table class='capmain' border='0' cellpadding='0' align='center'>
		<tr>
			<th>Kontrakter</th>
		</tr>
	</table>
	<table class='imagetable' border='0' cellpadding='5' align='center'>
		<tr>
			<th><b>Ansettelsesdato</b></th>
			
			<th><b>Oppsigelsesdato</b></th>
			
			<th><b>Stillingsprosent</b></th>
			
			<th><b>Ansatt Type</b></th>
			
			<th><b></b></th>
		</tr>
";

$i=0;
while ($i < $num) {
	$fra=mysql_result($result,$i,"ansettelsesdato");
	$til=mysql_result($result,$i,"oppsigelsesdato");
	$stilling=mysql_result($result,$i,"stillingsprosent");
	$ansatt=mysql_result($result,$i,"ansatt_type");
	$nyfra = date('d-M-Y', strtotime($fra));
	$nytil = date('d-M-Y', strtotime($til));
	$sid=mysql_result($result,$i,"arbeidskontraktid");
	++$i;
	echo "
		<form action='lagrekontrakt.php?confirm=ja&sid=".$sid."&avloserid=".$avloserid."&slett=ja&sjekk=nei' onSubmit='return validateUpdate()' method='post'>
		<tr>
			<td>$nyfra</td>
			<td>$nytil</td>
			<td>$stilling</td>
			<td>$ansatt</td>
			
			
			<td align=center><input type='submit' value='Slett'/></td>			
		</tr></form>
		";
} //Slutt på While-løkke

echo "	
		</table><br></br>
		<table class='capmain' border='0' cellpadding='0' align='center'>
		<tr>
			<th>Legg til ny Kontrakt</th>
		</tr>
		</table>
		
		<table class='imagetable' border='0' cellpadding='5' align='center' >	
		<form action='lagrekontrakt.php?avloserid=".$avloserid."&sjekk=ja' method='post'>";
		require_once('calendar/classes/tc_calendar.php');
		$myCalendar = new tc_calendar("date1", true);
		$myCalendar->setIcon("calendar/images/iconCalendar.gif");
		$myCalendar->setDate(01, 01, 2011);
		$myCalendar->setPath("calendar/");
		$myCalendar->setYearInterval(1970, 2037);
		$myCalendar->dateAllow('1970-01-01', '2037-12-31');
		$myCalendar2 = new tc_calendar("date2", true);
		$myCalendar2->setIcon("calendar/images/iconCalendar.gif");
		$myCalendar2->setDate(01, 01, 2011);
		$myCalendar2->setPath("calendar/");
		$myCalendar2->setYearInterval(1970, 2037);
		$myCalendar2->dateAllow('1970-01-01', '2037-12-31');
		echo" 	
		
	
			
			
				<tr>
					<th width='40%'>Ansettelsesdato:</th><th width='40%'>Oppsigelsesdato</th><th width='20%'>Stillingsprosent</th>
				<tr>
					<td width='40%'>";	$myCalendar->writeScript(); echo"  </td>		
					<td width='40%'>";  $myCalendar2->writeScript(); echo"  </td>
					<td width='20%'><Select name = 'stilling'>
						<Option value = '5%'>5%</Option>
						<Option value = '10%'>10%</Option>
						<Option value = '15%'>15%</Option>
						<Option value = '20%'>20%</Option>
						<Option value = '25%'>25%</Option>
						<Option value = '30%'>30%</Option>
						<Option value = '35%'>35%</Option>
						<Option value = '40%'>40%</Option>
						<Option value = '45%'>45%</Option>
						<Option value = '50%'>50%</Option>
						<Option value = '55%'>55%</Option>
						<Option value = '60%'>60%</Option>
						<Option value = '65%'>65%</Option>
						<Option value = '70%'>70%</Option>
						<Option value = '75%'>75%</Option>
						<Option value = '80%'>80%</Option>
						<Option value = '85%'>85%</Option>
						<Option value = '90%'>90%</Option>
						<Option value = '95%'>95%</Option>
						<Option value = '100%'>100%</Option></td>
				</tr>
				<tr>	
					<td width='40%'><b>Fast Ansatt:</b><input type='checkbox' name='type[]' value='Fast Ansatt'>&nbsp; &nbsp;<b>Tilkallingsvakt:</b><input type='checkbox' name='type[]' value='Tilkallingsvakt'></td>
					<td width='40%'></td>
					<td width='20%'><input type='Submit' value='Legg til'></td>	
				</tr></form>
			</table><br></br>
";

//---------------------------------------------------------------------------------------------------------------------+
//----------Slutt på kode for uthenting av kontraktdata fra DB og HTML printing til nettleser--------------------------+
//---------------------------------------------------------------------------------------------------------------------+
require_once THEMES."templates/footer.php";
?>
<!-- JavaScript and HTML codes by Quackit.com -->
<script language="javascript" type="text/javascript" >
function validateUpdate(){
		var confirmLeave = confirm('Er du sikker?');
		return confirmLeave;
}
</script>

